﻿using System;
using System.Data;
using System.Data.SQLite;

namespace FreeWorship
{
	public class DBUtil
	{
		public static SQLiteConnection connection=null;
		public static SQLiteCommand command = null;
		
		private static String BIBLE_DB = "cuvs.db";
		
		public DBUtil()
		{
		}
		
		public static DataTable GetDataTable (string sql)
		{
			DataTable dt = new DataTable();
			if(connection==null)
			{
			connection = new SQLiteConnection("Data Source="+BIBLE_DB);
			connection.Open();
			command = new SQLiteCommand(connection);
			}
			command.CommandText = sql;
			SQLiteDataReader reader = command.ExecuteReader();
			dt.Load(reader);
			reader.Close();

			return dt;
		}
		
		public static Object[] getBookList(string bookName)
	{
		DataTable table = GetDataTable(string.Format("select clong from book where clong like '{0}%' or cshort like '{0}%' or elong like '{0}%' or eshort like '{0}%' or pylong like '{0}%' or pyshort like '{0}%'",bookName));
		int rows=Math.Min(table.Rows.Count,5);
		Object[] items =new Object[rows];
		for(int i=0;i<rows;i++)
			items[i]=table.Rows[i][0];
		return items;
	}
	}
	
	
}
